Skip to content

Conversation

mzihlmann
Copy link

@mzihlmann mzihlmann commented May 22, 2025

I would like to add support for endpoints like this

@app.put("/user")
@app.route("/user/<user>")
def user(user = None):
    """user endpoint.

    ---
    get:
        description: get user details
        responses:
            200:
                description: a user to be returned
    put:
        description: create a user
        responses:
            200:
                description: some data
    """
    pass

that define different paths on top of the same handler. Currently this would result in wrong spec like this:

{
  "paths": {
    "/user/{user}": {
      "get": {
        "description": "get user details",
        "responses": {
          "200": {
            "description": "a user to be returned"
          }
        }
      },
      "put": {
        "description": "create a user",
        "responses": {
          "200": {
            "description": "some data"
          }
        }
      }
    }
  }
}

note that all methods get attributed to whatever path comes in last.

with this change we can render the correct data

{
  "paths": {
    "/user/{user}": {
      "get": {
        "description": "get user details",
        "responses": {
          "200": {
            "description": "a user to be returned"
          }
        }
      }
    },
    "/user": {
      "put": {
        "description": "create a user",
        "responses": {
          "200": {
            "description": "some data"
          }
        }
      }
    }
  }
}

note that for this to work, users must adapt the way they call into the library a bit.

- spec.path(view=view)
+ spec.path(rule=rule)

as based on the handler function alone we cannot deduce what path, and hence which methods, matched.

without this change users can circumvent this issue by splitting their handler functions up, s.t. we have a 1:1 mapping between endpoints and handlers.

please excuse the a bit nonsensical example.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant